<style>
    .btn-red{
        background-color: #F92659;
    }
    </style>
<section id="main-content">
    <section class="wrapper">
    <!-- page start-->
        <div class="row">
            <div class="col-lg-12">
                <section class="panel panel-info">
                    <header class="panel-heading">
                        签约区域查询--已签约区域颜色加重
                    </header>
                    <div class="panel-body">
                        <form class="navbar-form " role="search" method="post" target="_self">
                            <div class="col-lg-6 m-b">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label">
                                        <select name="type" id="type"  class="btn btn-default">
                                            <option value="">搜索方式</option>
                                            <option value="1" <?php echo !empty($data['type']) &&  $data['type']== 1 ? 'selected' :''; ?>>区域名称</option>
                                            <option value="2" <?php echo !empty($data['type']) &&  $data['type']== 2 ? 'selected' :''; ?>>城市名称</option>
                                        </select>
                                    </label>
                                    <div class="col-sm-3">
                                        <input type="text" class="form-control" name="title"  id="title" value="<?php echo !empty($data['title']) ? $data['title'] :'';?>">
                                    </div>
                                </div>
                                <button type="button" class="btn btn-info slecctformName">查询</button>
                            </div>
                            <div class="col-lg-6 m-b">
                                <div class="form-group">
                                    <select class="btn btn-default" name="province" id="province">
                                        <option value="">--省份--</option>
                                        <?php if(!empty($province)){foreach($province as $k => $v){?>
                                            <option value="<?php echo $v['id']?>" <?php if(!empty($data['province'] ) && $data['province'] == $v['id']){echo "selected";}?>><?= $v['name'];?></option>
                                        <?php }}?>
                                    </select>
                                    <select name="city" id="city"  class="btn btn-default">
                                        <?php if(!empty($city)){foreach($city as $k => $v){?>
                                            <option value="<?php echo $v['id']?>" <?php if(!empty($data['city'] ) && $data['city'] == $v['id']){echo "selected";}?>><?= $v['name'];?></option>
                                        <?php }}else{?>
                                        <option value="">--城市--</option>
                                        <?php }?>
                                    </select>
                                    <select name="sign" id="sign"  class="btn btn-default">
                                        <option value="">状态签约</option>
                                        <option value="1" <?php echo !empty($data['sign']) &&  $data['sign']== 1 ? 'selected' :''; ?>>未签约</option>
                                        <option value="2" <?php echo !empty($data['sign']) &&  $data['sign']== 2 ? 'selected' :''; ?>>已签约</option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-info slecctform">查询</button>
                            </div>
                        </form>
                    </div>
                    <ul class="list-group list-area">
                        <?php if(!empty($model)){foreach ($model as $k=>$v){?>
                            <li class= 'list-group-item <?php echo $v['isSign'] == 1 ? "label-success" :''?>'>
                                <span style="width: 20%;float: left;display: inline-block;vertical-align:middle"><?php echo !empty($v['areaName']) ? $v['areaName'] : '-';?></span>
                                <span style="width: 35%;;float: left;display: inline-block;vertical-align:middle"><?php echo !empty($v['message']) ? $v['message'] : '-';?></span>
                                <span style="width: 25%;;float: left;display: inline-block;vertical-align:middle"><?php echo !empty($v['cityName']) ? $v['cityName'] : '-';?></span>
                                <?php if(Yii::$app->cache->get('admin')['role'] != 3){?>
                                <span style="width: 20%;float: right;display: inline-block;vertical-align:middle">
                                    <input type="hidden" class="id" value="<?php echo $v['id']?>">
                                    <input type="hidden" class="is_sign" value="<?php echo $v['isSign']?>">
                                    <?php if($v['isSign'] == 0){ ?>
                                        <button type="button" class="btn btn-xs btn-primary demo1">签约确认</button>
                                    <?php }else{?>
                                        <button type="button" class="btn btn-xs btn-red demo1">取消签约</button>
                                    <?php }?>
                                </span>
                                <?php }?>
                            </li>
                        <?php }}?>
                    </ul>
                </section>
            </div>
        </div>
    <!-- page end-->
    </section>
</section>

<script src="/js/plugins/sweetalert/sweetalert.min.js"></script>
<script>
//省和市二级联动
$('#province').on('change', function () {
    var obj = $(this);
    if (!obj.val()) {
        $("#city").empty();
        $("#city").append("<option value=''>--城市--</option>");
        return false;
    }
    if (!$(this).hasClass('children')) {
        $.ajax({
            url: '/sign/get-list',
            type: 'post',
            dataType: 'json',
            data: "province="+obj.val(),
            success: function (res) {
                $("#city").empty();
                var html = "<option value=''>请选择</option>";
                for (a in res.data) {
                    html += '<option value="' + res.data[a].id + '" >' + res.data[a].name + '</option>';
                }
                $("#city").append(html);
            }
        });
    }
});

$(".slecctformName").click(function(){
    var str = "1=1";
    var title = $("#title").val();
    var type = $("#type").val();
    if(type.length == 0){
        alert('请选择搜索维度');
        return false;
    }else{
        str += "&type="+type;
    }
    if(title.length == 0){
        alert('请输入搜索内容');
        return false;
    }else{
        str += "&title="+title;
    }
    window.location.href='index?'+str;
});

$(".slecctform").click(function(){
    var str = "1=1";
    var city = $("#city").val();
    var sign = $("#sign").val();
    var province = $("#province").val();
    if(sign.length >= 0){
        str += "&sign="+sign;
    }
    if(province.length != 0){
        str += "&province="+province;
    }
    if(city.length != 0){
        str += "&city="+city;
    }
    window.location.href='index?'+str;
});
//签约确认
$('.demo1').click(function () {
    var id = $(this).siblings(".id").val();
    var is_sign = $(this).siblings(".is_sign").val();
    if(is_sign == 1){
        var title = "您确定取消该区域签约吗？";
        var submit = "取消签约";
    }else{
        var title = "该区域确定签约了吗？";
        var submit = "确定签约";
    }
    swal({
        title: title,
        text: "该操作很重要，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: submit,
        cancelButtonText: "让我再考虑一下…",
        closeOnConfirm: false,
        closeOnCancel: false
    }, function (isConfirm) {
        if (isConfirm) {
            $.ajax({
                type: "post",
                    url: "sign-ajax-do",
                    data: {id:id,isSign:is_sign},
                    dataType: "json",
                    success: function(param){
                    if(param.code == '20000'){
                        swal("操作成功！", param.message, "success");
                        location.reload();
                    }else{
                        swal("操作失败！", param.message, "error")
                    }
                  }
            });
        } else {
            swal("已取消", "您取消了该操作！", "error")
        }
    });
});
</script>
